import api from './api';
import {Utils} from './utils/Utils';
import {LoginForm} from './components/LoginForm';
import {Captcha} from './utils/Captcha';

export class App {
    constructor(selector){
        this.dom = $(selector);

        this.api = api;
        this.captcha = new Captcha();

        if(Utils.checkIsMobile()){
            this.loginMode = 'mobile';
        } else {
            this.loginMode = 'account';
        }

        this.loginForm = new LoginForm(this, this.dom);
        this.updateLoginMode();
    }

    setLoginMode(loginMode){
        this.loginMode = loginMode;
        this.loginForm.loginMode = loginMode;
        this.updateLoginMode();
    }

    updateLoginMode(){
        if(this.loginMode === 'mobile'){
            this.useMobileLogin();
        } else if(this.loginMode === 'account'){
            this.useAccountLogin();
        }
    }

    useAccountLogin(){
        this.dom.find('.d-mode-account').show();
        this.dom.find('.d-mode-mobile').hide();
    }

    useMobileLogin(){
        this.dom.find('.d-mode-mobile').show();
        this.dom.find('.d-mode-account').hide();
    }
}